package com.eunion.core;

import java.util.List;

import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;

import com.eunion.web.common.base.search.SearchOperator;

/**
 * 分页查询的条件.
 * 
 * @version 2016年4月19日 下午8:20:29
 */
public class PageConditions {

	/**
	 * 操作:相等,大于,升序等
	 */
	private String operator = SearchOperator.Conditon.eq;

	/**
	 * 键,operator针对的操作的键.
	 */
	private String key;

	/**
	 * 键对应的Java类型 , 默认string类型.
	 */
	private String type = SearchOperator.Type.string;

	/**
	 * 键值,operator针对的操作的键.
	 */
	private Object value;
	/**
	 * 键值,operator针对的操作的键 可以认为是最大值 .
	 */
	private Object value2;

	/**
	 * 批量值.
	 */
	private List<Object> valueList;

	public PageConditions() {
	}

	/**
	 * 一个构造方法.
	 * @param operator 操作
	 * @param key 键
	 * @param value 值
	 * @param value2 值2
	 * @param valueList 列表
	 */
	public PageConditions(String operator, String key, Object value, Object value2, List<Object> valueList) {
		this.operator = operator;
		this.key = key;
		this.value = value;
		this.value2 = value2;
		this.valueList = valueList;
	}

	/**
	 * 一个构造方法.
	 * @param operator 升降序
	 * @param key 键
	 */
	public PageConditions addOrder(String operator, String key) {
		this.operator = operator;
		this.key = key;
		return this;
	}

	/**
	 * 一个构造方法.
	 * @param operator 升降序
	 * @param key 键
	 * @param value  值
	 */
	public PageConditions addCondition(String operator, String key, Object value) {
		this.operator = operator;
		this.key = key;
		this.value = value;
		return this;
	}

	/**
	 * 一个构造方法.
	 * @param operator 操作
	 * @param key 键
	 * @param value 值
	 * @param value2 值2 
	 */
	public PageConditions addBetween(String operator, String key, Object value, Object value2) {
		this.operator = operator;
		this.key = key;
		this.value = value;
		this.value2 = value2;
		return this;
	}

	/**
	 * 一个构造方法.
	 * @param operator 操作
	 * @param key 键
	 * @param value 值
	 * @param value2 值2
	 * @param valueList 列表
	 */
	public PageConditions addCollections(String operator, String key, List<Object> valueList) {
		this.operator = operator;
		this.key = key;
		this.valueList = valueList;
		return this;
	}

	public String getOperator() {
		return operator;
	}

	public void setOperator(String operator) {
		this.operator = operator;
	}

	public String getKey() {
		return key;
	}

	public void setKey(String key) {
		this.key = key;
	}

	public Object getValue() {
		return value;
	}

	public void setValue(Object value) {
		this.value = value;
	}

	public Object getValue2() {
		return value2;
	}

	public void setValue2(Object value2) {
		this.value2 = value2;
	}

	public List<Object> getValueList() {
		return valueList;
	}

	public void setValueList(List<Object> valueList) {
		this.valueList = valueList;
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	@Override
	public String toString() {
		return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE);
	}
}
